package com.yh.homestay.service.impl;

import com.yh.homestay.dao.SysPermssionMapper;
import com.yh.homestay.dao.SysRoleMapper;
import com.yh.homestay.dao.SysRolePermissionMapper;
import com.yh.homestay.dao.SysStaffRoleMapper;
import com.yh.homestay.pojo.SysPermission;
import com.yh.homestay.pojo.SysRole;
import com.yh.homestay.pojo.SysRolePermission;
import com.yh.homestay.pojo.SysStaffRole;
import com.yh.homestay.service.SysPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName SysPermissionServiceImpl
 * @Description TODO
 * @Author GCL
 * @Date 2020/1/6 15:17
 */
@Service
public class SysPermissionServiceImpl implements SysPermissionService {

    @Autowired
    private SysStaffRoleMapper sysStaffRoleMapper;

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public List<SysPermission> getUrlList(Integer staffId) {
//        //查询出角色信息
//        SysStaffRole sysStaffRole = sysStaffRoleMapper.selectByPrimaryKey(staffId);
//        //查询出permission信息
//        Example example = new Example(SysRolePermission.class);
//        example.createCriteria().andEqualTo("roleId", sysStaffRole.getRoleId());
//        List<SysRolePermission> sysRolePermissions = sysRolePermissionMapper.selectByExample(example);
//        //查询出对应的SysPermision集合
//        List<SysPermission> permissions = new ArrayList<SysPermission>();
//        for (SysRolePermission sysRolePermission : sysRolePermissions) {
//            SysPermission sysPermission = sysPermssionMapper.selectByPrimaryKey(sysRolePermission.getPermissionId());
//            permissions.add(sysPermission);
//        }
        Example example = new Example(SysStaffRole.class);
        example.createCriteria().andEqualTo("staffId",staffId);
        List<SysStaffRole> staffRoles = sysStaffRoleMapper.selectByExample(example);
        List<String> roles = new ArrayList<String>();
        for (SysStaffRole staffRole:staffRoles) {
            SysRole sysRole = sysRoleMapper.selectByPrimaryKey(staffRole.getRoleId());
            roles.add(sysRole.getRoleName());
        }
        return null;
    }
}
